package fy.erp.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;

import fy.config.FyConfig;
import fy.erp.bean.QueryCustomerBean;
import fy.util.DBUtil;
//新产品立项报告
public class QueryCustomerNameDao {

	private static Log log = LogFactory.getLog(QueryCustomerNameDao.class);

	private String[] codes;


	private final static String queryCustomer = "SELECT t.customer_number, t.customer_name FROM apps.ar_customers t WHERE t.customer_number = ? ";

	public JSONObject queryCustomer(String customer_number) {
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		JSONObject jo = new JSONObject();
		try {
			conn = DBUtil.connect(FyConfig.getERP_DB_CONFIG());
			pst = conn.prepareStatement(queryCustomer);
			pst.setString(1, customer_number);
			rs = pst.executeQuery();
			while (rs.next()) {
				QueryCustomerBean qcb=new QueryCustomerBean();
				qcb.setCustomerCode(rs.getString(1));
				qcb.setCustomerName(rs.getString(2));
			/*	PersonInfoBean pib = new PersonInfoBean();
				pib.setCode(rs.getString(1));*/
				/*System.out.println("123"+rs.getString(1));
				System.out.println("123"+rs.getString(2));*/
				jo.put(qcb.getID(), qcb.getJSONObject());
			}
		} catch (Exception e) {
			log.error("查找人员信息出错", e);
			e.printStackTrace();
		} finally {
			DBUtil.close(rs);
			DBUtil.close(pst);
			DBUtil.close(conn);
		}

		return jo;
	}

	public void setCodes(String[] codes) {
		this.codes = codes;
	}

	/*private String getSQL() {
		StringBuilder sb = new StringBuilder();

		sb.append(needTime ? yingongSQL : chuchaiSQL);

		for (int i = 0, length = this.codes.length; i < length; i++) {
			if (i == 0) {
				sb.append(" and ( tab1.psncode=? ");
			} else {
				sb.append(" or tab1.psncode=? ");
			}
		}
		sb.append(" ) ");

		return sb.toString();
	}
*/
/*	private void setParams(PreparedStatement st) throws Exception {
		for (int i = 0, length = this.codes.length; i < length; i++) {
			st.setString(i + 1, this.codes[i]);
		}
	}*/

	
}
